package com.my.thread.syncRetuen.threadLocal;

import com.my.thread.syncRetuen.service.SpringThreadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author timo 2021/3/18
 */
@RestController
@Slf4j
public class SpringTestController2 {
    @Autowired
    private SpringThreadService serviceImpl;

    @RequestMapping("/test")
    @ResponseBody
    public String testMyThreadLocal() {
        //只针对同一个线程，子线程不起作用，类似下面 helloFuture
        MyThreadLocal.set("123");
        serviceImpl.testMyThreadLocal();
        return "123";
    }
    @RequestMapping("/test2")
    @ResponseBody
    public String testMyThreadLocal2() {
        Object o = MyThreadLocal.get();
        System.out.println(o);
        return "12";
    }
}
